package com.qingchi.server.controller;

import com.socialuni.social.constant.status.StatusConst;
import com.qingchi.base.model.system.HomeSwiperDO;
import com.qingchi.base.repository.config.HomeSwiperRepository;
import com.qingchi.base.utils.DevAccountUtils;
import com.socialuni.social.api.AppApi;
import com.socialuni.social.model.HomeSwiperVO;
import com.socialuni.social.model.common.ResultRO;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class AppController implements AppApi {
    @Resource
    private HomeSwiperRepository homeSwiperRepository;

    @Override
    public ResultRO<List<HomeSwiperVO>> queryHomeSwipers() {
        List<HomeSwiperDO> homeSwiperDOS = homeSwiperRepository.findAllByStatusAndDevIdOrderByTopLevelAscIdDesc(StatusConst.enable, DevAccountUtils.getDevId());
        return new ResultRO<>(homeSwiperDOS.stream().map(HomeSwiperDO::toVO).collect(Collectors.toList()));
    }
}